package com.oa.hyperion.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oa.hyperion.entity.Department;
import com.oa.hyperion.repository.Base.DepartmentMapper;
import com.oa.hyperion.repository.Base.EmployeeMapper;
import com.oa.hyperion.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Liu
 * @date 2022年01月17日 14:02
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper,Department> implements DepartmentService {

    @Resource
    private DepartmentMapper departmentMapper;

    @Resource
    private EmployeeMapper employeeMapper;

    /**
     * 使用mybatis-plus来完成 多表查询
     * @return
     */
    @Override
    public List<Department> getAllDepart() {
        //获取所有可用部门
        QueryWrapper<Department> wrapper=new QueryWrapper<>();
        wrapper.eq("status","y");
        List<Department> list=departmentMapper.selectList(wrapper);
            //遍历所有部门,逐个设置leader 属性,根据 header 属性来
            for(Department de:list) {
                de.setLeader(employeeMapper.selectById(de.getHeader()));
            }

        return list;
    }
}
